package com.sitech.portal.system.dao.ibatis;

import java.util.HashMap;
import java.util.List;

import com.sitech.ibnms.core.BaseIbnmsDao;
import com.sitech.ibnms.core.IPage;
import com.sitech.ibnms.core.PageForm;
import com.sitech.portal.system.dao.ISysWorkGroupDao;
import com.sitech.portal.system.domain.TblSYS_WORKGROUP;

public class SysWorkGroupDaoImpl extends BaseIbnmsDao implements ISysWorkGroupDao {

	@Override
	public void deleteWorkGroup(String id) {
		this.delete("deleteWorkGroup", id);
	}

	@Override
	public List<HashMap> findWorkGroupByParentId(String parentId) {
		HashMap map = new HashMap();
		map.put("SUPER_WG", parentId);
		return this.query("findWorkGroupByParentId", map);
	}
	
	@Override
	public List<HashMap> findWorkGroupByParentIdUser(String parentId,String userId){
		HashMap map = new HashMap();
		map.put("SUPER_WG", parentId);
		map.put("USER_ID", userId);
		return this.query("findWorkGroupByParentIdUser", map);
	}

	@Override
	public IPage finedUsersOfWorkGroup(String workGroup_id, PageForm pageForm){
		HashMap map = new HashMap();
		map.put("WORKGROUP_ID", workGroup_id);
		return this.findPage("finedUsersOfWorkGroup", map, pageForm);
	}

	@Override
	public void insertWorkGroup(TblSYS_WORKGROUP wp) {
		try{
			this.insert("insertWorkGroup", wp);
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	@Override
	public void updateWorkGroup(TblSYS_WORKGROUP wp) {
		this.update("updateWorkGroup", wp);
	}
	
	public List<HashMap> findAllWorkGroup(){
		return this.query("findAllWorkGroup");
	}

	@Override
	public TblSYS_WORKGROUP findWorkGroupById(String id) {
		HashMap map = new HashMap();
		map.put("WORKGROUP_ID", id);
		return (TblSYS_WORKGROUP)this.querySingle("findWorkGroupById", map);
	}

	@Override
	public void deleteUserFromWorkGroup(String login_id,String workGroupId) {
		HashMap map = new HashMap();
		map.put("LOGIN_ID", login_id);
		map.put("WORKGROUP_ID", workGroupId);
		this.delete("deleteUserFromWorkGroup", map);
	}

	@Override
	public void insertUserToWorkGroup(String login_id,String workGroupId) {
		HashMap map = new HashMap();
		map.put("LOGIN_ID", login_id);
		map.put("WORKGROUP_ID", workGroupId);
		this.insert("insertUserToWorkGroup", map);
	}

	@Override
	public void deleteAllUserFromWorkGroup(String workGroupId) {
		HashMap map = new HashMap();
		map.put("WORKGROUP_ID", workGroupId);
		this.delete("deleteUserFromWorkGroup", map);
	}

    @Override
    public void deleteWorkGroupByUser(String id) {
        this.delete("deleteWorkGroupByUser", id);
    }

    @Override
	public List findUserOfWorkGroup(String login_id, String workGroup_id) {
		HashMap map = new HashMap();
		map.put("WORKGROUP_ID", workGroup_id);
		map.put("LOGIN_ID", login_id);
		return this.query("finedUsersOfWorkGroup", map);
	}
	
	public List findUserOfWorkGroup(String workGroup_id){
		HashMap map = new HashMap();
		map.put("WORKGROUP_ID", workGroup_id);
		return this.query("finedUsersOfWorkGroup", map);
	}
	
	public List findWorkGroupOfUser(String login_id){
		HashMap map = new HashMap();
		map.put("LOGIN_ID", login_id);
		return this.query("findWorkGroupOfUser", map);
	}
}
